package com.zwc.angle2048;

import android.graphics.Typeface;
import android.view.MotionEvent;

import com.zwc.angle.AngleActivity;
import com.zwc.angle.AngleFont;
import com.zwc.angle.AngleObject;
import com.zwc.angle.AngleSprite;
import com.zwc.angle.AngleSpriteLayout;
import com.zwc.angle.AngleString;
import com.zwc.angle.AngleUI;

/**
 * 游戏目录界面
 * 
 * @author zwc
 */
public class UIOfMenu extends AngleUI {
	private AngleObject groupOfMenu;
	private AngleString strClassic;
	private AngleString strTime;
	private AngleString strUnlimited;
	private AngleString strHiScore;
	private AngleString strExit;

	public UIOfMenu(AngleActivity activity) {
		super(activity);

		int width = GameUtil.WIDTH;
		int height = GameUtil.HEIGHT;

		addObject(new AngleSprite(width / 2, height / 2, new AngleSpriteLayout(
				mActivity.mGLSurfaceView, width, height,
				com.zwc.angle2048.R.drawable.bg)));

		groupOfMenu = new AngleObject();
		addObject(groupOfMenu);

		AngleFont fntHoneyLight = new AngleFont(mActivity.mGLSurfaceView, 70,
				Typeface.createFromAsset(mActivity.getAssets(),
						"HoneyLight.ttf"), 222, 0, 0, 30, 200, 255, 255);
		AngleFont fntAddElectricCity = new AngleFont(mActivity.mGLSurfaceView,
				40, Typeface.createFromAsset(mActivity.getAssets(),
						"AddElectricCity.ttf"), 200, 0, 0, 255, 0, 0, 255);

		groupOfMenu.addObject(new AngleString(fntHoneyLight, "2048", width / 2,
				height * 3 / 16, AngleString.aCenter));
		strClassic = (AngleString) groupOfMenu.addObject(new AngleString(
				fntAddElectricCity, "Classic Mode", width / 2, height * 6 / 16,
				AngleString.aCenter));
		strTime = (AngleString) groupOfMenu.addObject(new AngleString(
				fntAddElectricCity, "Time Mode", width / 2, height * 8 / 16,
				AngleString.aCenter));
		strUnlimited = (AngleString) groupOfMenu.addObject(new AngleString(
				fntAddElectricCity, "Unlimited Mode", width / 2,
				height * 10 / 16, AngleString.aCenter));
		strHiScore = (AngleString) groupOfMenu.addObject(new AngleString(
				fntAddElectricCity, "High Score", width / 2, height * 12 / 16,
				AngleString.aCenter));
		strExit = (AngleString) groupOfMenu.addObject(new AngleString(
				fntAddElectricCity, "Exit", width / 2, height * 14 / 16,
				AngleString.aCenter));
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			float eX = event.getX();
			float eY = event.getY();
			if (strClassic.test(eX, eY)) {
				((MainActivity) mActivity)
						.setUI(((MainActivity) mActivity).mTheGameClassic);
			} else if (strTime.test(eX, eY)) {
				((MainActivity) mActivity)
						.setUI(((MainActivity) mActivity).mTheGameTime);
			} else if (strUnlimited.test(eX, eY)) {
				((MainActivity) mActivity)
						.setUI(((MainActivity) mActivity).mTheGameUnlimited);
			} else if (strHiScore.test(eX, eY)) {
				((MainActivity) mActivity)
						.setUI(((MainActivity) mActivity).mTheGameHiScore);
			} else if (strExit.test(eX, eY)) {
				mActivity.finish();
			}

			return true;
		}
		return false;
	}

	@Override
	public void onActivate() {
		super.onActivate();
	}

}
